package lanou3g.myfirstapp36kr.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

//import it.sephiroth.android.library.picasso.Picasso;
import com.squareup.picasso.Picasso;

import lanou3g.myfirstapp36kr.R;
import lanou3g.myfirstapp36kr.base.BaseActivity;
import lanou3g.myfirstapp36kr.entity.ActivityNearfutureActivityEntity;

/**
 * Created by dllo on 16/8/7.
 */
public class ActivityNearfutureActivityAdapter extends BaseAdapter {
    private Context context;
    private ActivityNearfutureActivityEntity entity;

    public ActivityNearfutureActivityAdapter(Context context) {
        this.context = context;
    }

    public void setEntity(ActivityNearfutureActivityEntity entity) {
        this.entity = entity;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return entity.getData().getData().size();
    }

    @Override
    public Object getItem(int i) {
        return entity.getData().getData().get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_activity_nearfuture_activity_lv,null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        Picasso.with(context).load(entity.getData().getData().get(i).getActivityImg()).into(viewHolder.imageViewPicture);
        viewHolder.textViewName.setText(entity.getData().getData().get(i).getActivityName());
        viewHolder.textViewDesc.setText(entity.getData().getData().get(i).getActivityDesc());
        viewHolder.textViewStatuse.setText(entity.getData().getData().get(i).getActivityStatus());
        viewHolder.textViewCity.setText(entity.getData().getData().get(i).getActivityCity());
        viewHolder.textViewTime.setText(entity.getData().getData().get(i).getActivityTime());
        return view;
    }
    private class ViewHolder{
        private ImageView imageViewPicture;
        private TextView textViewName;
        private TextView textViewDesc;
        private TextView textViewStatuse;
        private TextView textViewCity;
        private TextView textViewTime;
        public ViewHolder(View view) {
            imageViewPicture = (ImageView) view.findViewById(R.id.iv_picture);
            textViewName = (TextView) view.findViewById(R.id.tv_act_name);
            textViewDesc = (TextView) view.findViewById(R.id.tv_act_desc);
            textViewStatuse = (TextView) view.findViewById(R.id.tv_act_status);
            textViewCity = (TextView) view.findViewById(R.id.tv_act_city);
            textViewTime = (TextView) view.findViewById(R.id.tv_act_time);
        }
    }
}
